package day10.collections.List;

/*
 * Author: JacksonCoder
 * FileName: LinkedListDemo
 * Version: 1.0.0
 * Date: 2025/4/17
 */

import java.util.LinkedList;

public class LinkedListDemo {
    public static void main(String[] args) {

        LinkedList<String> list = new LinkedList<>();

        // 插入
        list.add("Java");
        list.add("Python");
        list.add("GoLang");

        // 头插
        list.addFirst("C");

        //尾插
        list.addLast("C++");
        list.addLast("Rust");

        // 访问元素
        System.out.println(list.get(1));
        System.out.println(list.getFirst());
        System.out.println(list.getLast());

        // 修改元素
        list.set(list.size() - 1 , "C#");

        // 删除元素
        list.remove("Java");
        list.removeFirst();
        list.removeLast();

        // 遍历
        for(String item : list){
            System.out.println("item: " + item);
        }




    }
}
